package com.hhsj.dynamicui.model;

import java.io.Serializable;

/**
 * 视图属性有基本属性
 * 和特定属性
 * 1，形状（圆，方）
 * 2，内间距
 * 3，外间距
 * 4，圆角（形状为方时）
 * 5，背景（颜色值）
 */
public final class WidgetProperty implements Serializable {

    private Round round;
    private Padding padding;
    private Margin margin;
    private Background background;
    private WHSize whSize;

    public Round getRound() {
        return round;
    }

    public Padding getPadding() {
        return padding;
    }

    public Margin getMargin() {
        return margin;
    }

    public Background getBackground() {
        return background;
    }

    public WHSize getWhSize() {
        return whSize;
    }

    public static class Round {
        private int radius = 0;//半径
        private int roundType = 0;//0，方，1，圆，2圆角
        private boolean cornerTopLeft = false;//0，关，1，开
        private boolean cornerTopRight = false;
        private boolean cornerBottomLeft = false;
        private boolean cornerBottomRight = false;

        public int getRadius() {
            return radius;
        }

        public int getRoundType() {
            return roundType;
        }

        public boolean isCornerTopLeft() {
            return cornerTopLeft;
        }

        public boolean isCornerTopRight() {
            return cornerTopRight;
        }

        public boolean isCornerBottomLeft() {
            return cornerBottomLeft;
        }

        public boolean isCornerBottomRight() {
            return cornerBottomRight;
        }
    }

    public static class Padding {
        private int paddingTop = 0;
        private int paddingBottom = 0;
        private int paddingLeft = 0;
        private int paddingRight = 0;

        public int getPaddingTop() {
            return paddingTop;
        }

        public int getPaddingBottom() {
            return paddingBottom;
        }

        public int getPaddingLeft() {
            return paddingLeft;
        }

        public int getPaddingRight() {
            return paddingRight;
        }
    }

    public static class Margin {
        private int marginLeft = 0;
        private int marginTop = 0;
        private int marginRight = 0;
        private int marginBottom = 0;

        public int getMarginLeft() {
            return marginLeft;
        }

        public int getMarginTop() {
            return marginTop;
        }

        public int getMarginRight() {
            return marginRight;
        }

        public int getMarginBottom() {
            return marginBottom;
        }
    }

    public static class WHSize {
        private int whRelation = 0;//宽高关系模式
        private int height = 0;
        private int width = 0;
        private float rWidth = 1;//width/ height 宽高比 -1,不会取，>0
        private float rHeight = 1;//width/ height 宽高比 -1,不会取，>0

        public int getWhRelation() {
            return whRelation;
        }

        public int getHeight() {
            return height;
        }

        public int getWidth() {
            return width;
        }

        public float getRWidth() {
            return rWidth;
        }

        public float getRHeight() {
            return rHeight;
        }
    }

    public static class Background {
        //只有3总，0表示无，1，表示颜色int，2，表示本地的某种颜色
        private int backgroundType = 0;
        private String backgroundColorStr = null;//颜色ARGB，需要解析
        private String backgroundColorEnum = null;//颜色名称，需要本地映射

        public int getBackgroundType() {
            return backgroundType;
        }

        public String getBackgroundColorStr() {
            return backgroundColorStr;
        }

        public String getBackgroundColorEnum() {
            return backgroundColorEnum;
        }
    }

    private WidgetProperty() {
        background = new Background();
        padding = new Padding();
        margin = new Margin();
        round = new Round();
        whSize = new WHSize();
    }

    public static class Builder {

        private int whRelation = 1;//宽高关系
        private int height;//宽
        private int width;//高
        private float rWidth;//宽：高的宽
        private float rHeight;//宽：高的高

        //margin
        private int marginTop;
        private int marginLeft;
        private int marginRight;
        private int marginBottom;

        //padding
        private int paddingLeft;
        private int paddingRight;
        private int paddingBottom;
        private int paddingTop;

        //bound
        private int roundType;//0，不是圆也不是圆角，1，圆，2，圆角
        private int radius;//圆角半径。暂时所有圆角半径都相等
        private boolean cornerTopLeft;//0，关，1，开
        private boolean cornerTopRight;
        private boolean cornerBottomLeft;
        private boolean cornerBottomRight;

        //background
        private int backgroundType;//0，无，1，颜色int值，2，固定的某个定义好的颜色，需要映射
        private String backgroundColorStr;//0xAARRGGBB
        private String backgroundColorEnum;//resId name;

        public Builder setWhRelation(int whRelation) {
            this.whRelation = whRelation;
            return this;
        }

        public Builder setrWidth(float rWidth) {
            this.rWidth = rWidth;
            return this;
        }

        public Builder setrHeight(float rHeight) {
            this.rHeight = rHeight;
            return this;
        }

        public Builder setRoundType(int roundType) {
            this.roundType = roundType;
            return this;
        }

        public Builder setCornerTopLeft(boolean cornerTopLeft) {
            this.cornerTopLeft = cornerTopLeft;
            return this;
        }

        public Builder setCornerTopRight(boolean cornerTopRight) {
            this.cornerTopRight = cornerTopRight;
            return this;
        }

        public Builder setCornerBottomLeft(boolean cornerBottomLeft) {
            this.cornerBottomLeft = cornerBottomLeft;
            return this;
        }

        public Builder setCornerBottomRight(boolean cornerBottomRight) {
            this.cornerBottomRight = cornerBottomRight;
            return this;
        }

        public Builder setBackgroundType(int backgroundType) {
            this.backgroundType = backgroundType;
            return this;
        }

        public Builder setBackgroundColorEnum(String backgroundColorEnum) {
            this.backgroundColorEnum = backgroundColorEnum;
            return this;
        }

        public Builder setHeight(int height) {
            this.height = height;
            return this;
        }

        public Builder setWidth(int width) {
            this.width = width;
            return this;
        }

        public Builder setMarginTop(int marginTop) {
            this.marginTop = marginTop;
            return this;
        }

        public Builder setMarginLeft(int marginLeft) {
            this.marginLeft = marginLeft;
            return this;
        }

        public Builder setMarginRight(int marginRight) {
            this.marginRight = marginRight;
            return this;
        }

        public Builder setMarginBottom(int marginBottom) {
            this.marginBottom = marginBottom;
            return this;
        }

        public Builder setPaddingLeft(int paddingLeft) {
            this.paddingLeft = paddingLeft;
            return this;
        }

        public Builder setPaddingRight(int paddingRight) {
            this.paddingRight = paddingRight;
            return this;
        }

        public Builder setPaddingBottom(int paddingBottom) {
            this.paddingBottom = paddingBottom;
            return this;
        }

        public Builder setPaddingTop(int paddingTop) {
            this.paddingTop = paddingTop;
            return this;
        }

        public Builder setBackgroundColorStr(String backgroundColorStr) {
            this.backgroundColorStr = backgroundColorStr;
            return this;
        }


        public Builder setRadius(int radius) {
            this.radius = radius;
            return this;
        }

        public WidgetProperty create() {
            WidgetProperty config = new WidgetProperty();
            config.whSize.whRelation = this.whRelation;
            config.whSize.height = this.height;
            config.whSize.width = this.width;
            config.whSize.rWidth = this.rWidth;
            config.whSize.rHeight = this.rHeight;

            config.margin.marginBottom = this.marginBottom;
            config.margin.marginTop = this.marginTop;
            config.margin.marginLeft = this.marginLeft;
            config.margin.marginRight = this.marginRight;

            config.padding.paddingLeft = this.paddingLeft;
            config.padding.paddingRight = this.paddingRight;
            config.padding.paddingTop = this.paddingTop;
            config.padding.paddingBottom = this.paddingBottom;

            config.background.backgroundType = this.backgroundType;//0，无，1，颜色int值，2，固定的某个定义好的颜色，需要映射
            config.background.backgroundColorStr = this.backgroundColorStr;
            config.background.backgroundColorEnum = this.backgroundColorEnum;//resId name;

            config.round.roundType = this.roundType;
            config.round.radius = this.radius;
            config.round.cornerTopLeft = this.cornerTopLeft;
            config.round.cornerTopRight = this.cornerTopRight;
            config.round.cornerBottomLeft = this.cornerBottomLeft;
            config.round.cornerBottomRight = this.cornerBottomRight;
            return config;
        }
    }
}
